const { Controller } = require('egg');

class HomeController extends Controller {


  /**
   * @api {GET} /product/inventory/list 获取出入库列表
   * @apiName list
   * @apiGroup inventory
   * @apiVersion 1.0.0
   *
   * @apiRequest json
   * @apiQuery  { String } name 名称
   * @apiQuery  { String } barcode 条码
   * @apiQuery  { String } type 类型
   * @apiQuery  { String } order 排序字段
   * @apiQuery  { String } method 排序方式
   * @apiQuery  { Number } pageIndex 页码
   * @apiQuery  { Number } pageSize 页面容量
   *
   * @apiHeader { String } Authorization 注册信息
   */
  async list() {
    const ctx = this.ctx;
    const app = this.app;
    try {

      const value = ctx.query;

      const { name, barcode, type, order, method, pageIndex, pageSize } = await app.rule.inventory.list(value);

      const data = await ctx.service.inventory.list(name, barcode, type, order, method, pageIndex, pageSize);
      ctx.status = 200;
      ctx.sendSuccess({ data });
      return;
    } catch (error) {
      ctx.status = 200;
      ctx.sendFailed({ msg: error.message });
      return;
    }
  }
}

module.exports = HomeController;
